//
//  VisitorLoginView.swift
//  SinaWeibo_18.1
//
//  Created by sun on 15/10/6.
//  Copyright © 2015年 孙美玲. All rights reserved.
//

import UIKit

//起草协议
protocol VisitorLoginViewDelegate:NSObjectProtocol{

    //协议方法
    func visitorWillRegister()
    func visitorWillLogin()
    

}

class VisitorLoginView: UIView {

    @IBOutlet weak var houseView: UIImageView!

    @IBOutlet weak var labelText: UILabel!

    @IBOutlet weak var smallIcon: UIImageView!
    
    weak var visitorDelegate:VisitorLoginViewDelegate?
    
    
    func setUpLoginView(imageName: String , tipText: String , isHome:Bool = false){
    
    houseView.image = UIImage(named: imageName)
        labelText.text = tipText
        smallIcon.hidden = !isHome
        if isHome{
        
    startAnimation()
            
        }
    
    
    }

    private func startAnimation(){
    
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.toValue = 2 * M_PI
        anim.duration = 20
        anim.repeatCount = MAXFLOAT
        
        //动画处于非活跃状态不移除
        anim.removedOnCompletion = false
        
        smallIcon.layer.addAnimation(anim, forKey: nil)
    
    }
    
    
    
    
    
    
    @IBAction func didLoginClick(sender: AnyObject) {
        visitorDelegate?.visitorWillLogin()
    }
    
    @IBAction func didRegisterClick(sender: AnyObject) {
        visitorDelegate?.visitorWillRegister()
    }

    
}
